﻿using Microsoft.EntityFrameworkCore;
using ProductDemo.Models;

namespace ProductDemo.Infrastructure
{
    public class ApplicationDbContext : DbContext
    {
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }

        public DbSet<Product> Products { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Product>()
                .HasKey(p => p.ProductId); // 设置主键

            modelBuilder.Entity<Product>().HasData(
                new Product { ProductId = 1, ProductName = "产品1", Description = "描述1", Price = 10.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 2, ProductName = "产品2", Description = "描述2", Price = 20.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 3, ProductName = "产品3", Description = "描述3", Price = 30.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 4, ProductName = "产品4", Description = "描述4", Price = 40.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 5, ProductName = "产品5", Description = "描述5", Price = 50.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 6, ProductName = "产品6", Description = "描述6", Price = 60.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 7, ProductName = "产品7", Description = "描述7", Price = 70.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 8, ProductName = "产品8", Description = "描述8", Price = 80.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 9, ProductName = "产品9", Description = "描述9", Price = 90.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 10, ProductName = "产品10", Description = "描述10", Price = 100.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 11, ProductName = "产品11", Description = "描述11", Price = 110.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 12, ProductName = "产品12", Description = "描述12", Price = 120.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 13, ProductName = "产品13", Description = "描述13", Price = 130.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 14, ProductName = "产品14", Description = "描述14", Price = 140.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 15, ProductName = "产品15", Description = "描述15", Price = 150.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 16, ProductName = "产品16", Description = "描述16", Price = 160.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 17, ProductName = "产品17", Description = "描述17", Price = 170.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 18, ProductName = "产品18", Description = "描述18", Price = 180.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 19, ProductName = "产品19", Description = "描述19", Price = 190.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) },
                new Product { ProductId = 20, ProductName = "产品20", Description = "描述20", Price = 200.0, CreatedDate = new DateTime(2024, 12, 20, 11, 37, 10) }
            );
        }
    }
}
